
const { where } = require('sequelize')
const Order = require('../model/Order.model')

class OrderService {
    async createOrder(order) {
        return await Order.create(order)
    }
    async updateOrder(id, state) {
        return await Order.update({ state }, { where: { id } })
    }
    async findAllOrder(pageNum, pageSize, state, user_id) {

        const offset = (pageNum - 1) * pageSize
        const { count, rows } = await Order.findAndCountAll({
            attributes: ['address_id', 'goods_info', 'oredr_number', 'state', 'id'],
            offset: offset,
            limit: pageSize * 1,
            where: {
                state,
                user_id
            },

        })

        return {
            pageNum,
            pageSize,
            total: count,
            list: rows
        }
    }
}

module.exports = new OrderService()